package com.nkzy.controller;

import com.nkzy.domain.pojo.Dept;
import com.nkzy.domain.pojo.Result;
import com.nkzy.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RequestMapping("/depts")
@RestController
public class DeptController {
    
    @Autowired
    private DeptService deptService;
    @GetMapping("/all")
    public Result getAllDepts() {
        List<Dept> depts = deptService.selectAll();
        return Result.success(depts);
    }
    @PostMapping
    public Result insertDept(@RequestBody Dept dept) {
        deptService.insertDept(dept);
        return Result.success();
    }
    @PutMapping
    public Result updateDept(@RequestBody Dept dept) {
        deptService.update(dept);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteDept(@PathVariable Integer id) {
        deptService.deleteById(id);
        return Result.success();
    }
}